/*===============================================
*   文件名称：jp.c
*   创 建 者：     
*   创建日期：2023年10月22日
*   描    述：
================================================*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include "camera.h"

int main()
{
    int came_fd,fd;
    unsigned int w,h,size,index;
    char *buf;
    w = 640;
    h = 480;

    came_fd = camera_init("/dev/video0",&w,&h,&size);
    if(fd == -1)
    {
        printf("open error\n");
        return -1;
    }

    int ret = camera_start(came_fd);
    if(ret == -1)
    {
        printf("start error\n");
        return -1;
    }
    
    ret = camera_dqbuf(came_fd,(void **)&buf,&size,&index);
    if(ret == -1)
    {       
        printf("qdbuf error\n");
        return -1;
    }

    fd = open("./1.jpg",O_WRONLY|O_CREAT,0644);
    if(fd == -1)
    {
        perror("open");
        return -1;
    }
    write(fd,buf,size);
    camera_eqbuf(came_fd,index);
    camera_stop(came_fd);
    camera_exit(came_fd);
    close(fd);

    return 0;
}
